package tests;

import io.ClassRoomReader;
import io.TimeTablesReader;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;

import manager.Manager;

import org.junit.Assert;
import org.junit.Test;

import entities.ClassRoom;
import entities.Course;
import entities.TimeTableColumn;
import entities.TimeTableRow;

public class Test_Manager {
	/*
	 * check the calculatePrecentage function test the percentage correct or not
	 * when the capacity is 50
	 */
	@Test
	public void test1() throws FileNotFoundException, IOException {
		boolean result;
		Course c = new Course("CS3201", 3, 1, "mark");
		result = (new Manager()).calculatePrecentage(c);
		Assert.assertEquals(result, false);
	}

	/*
	 * check the calculatePrecentage function test the percentage correct or not
	 * when the capacity is 50
	 */
	@Test
	public void test50() throws FileNotFoundException, IOException {
		boolean result;
		Course c = new Course("CS3201", 3, 50, "mark");
		result = (new Manager()).calculatePrecentage(c);
		Assert.assertEquals(result, false);
	}

	/*
	 * check the calculatePrecentage function test the percentage correct or not
	 * when the capacity is 200
	 */
	@Test
	public void test100() throws FileNotFoundException, IOException {
		boolean result;
		Course c = new Course("CS3201", 3, 200, "mark");
		result = (new Manager()).calculatePrecentage(c);
		Assert.assertEquals(result, true);
	}

	/*
	 * check the calculatePrecentage function test the percentage correct or not
	 * when the capacity is 300
	 */
	@Test
	public void test300() throws FileNotFoundException, IOException {
		boolean result;
		Course c = new Course("CS3201", 3, 300, "mark");
		result = (new Manager()).calculatePrecentage(c);
		Assert.assertEquals(result, true);
	}

	/*
	 * check the calculatePrecentage function test the percentage correct or not
	 * when the capacity is 400
	 */
	@Test
	public void test400() throws FileNotFoundException, IOException {
		boolean result;
		Course c = new Course("CS3201", 3, 400, "mark");
		result = (new Manager()).calculatePrecentage(c);
		Assert.assertEquals(result, false);
	}

	/*
	 * test the checknull function in Manager()
	 */
	@Test
	public void testChecknull() throws FileNotFoundException, IOException {
		boolean result;
		ClassRoom res;
		Course courseTable;
		res = new ClassRoom("4412", "AC2", 200, "Red");
		courseTable = new Course("CS3343", 3, 180, "Mary Wong");
		result = (new Manager()).checknull(res, courseTable);
		Assert.assertEquals(result, true);
	}

	@Test
	public void testChecknull02() throws FileNotFoundException, IOException {
		boolean result = true;
		ClassRoom res;
		res = new ClassRoom("4412", "AC2", 200, "Red");
		ArrayList<Course> timeTableEntries = new ArrayList<Course>();
		timeTableEntries.add(new Course("CS3201", 3, 200, "mark"));

		int i = 0;
		for (Course rr : timeTableEntries) {

			for (TimeTableRow row : res.get_timetable()) {

				for (TimeTableColumn column : row) {
					i++;
					column.setClass(rr);

					if (i == 9)
						break;
				}
			}
		}

		for (Course row : timeTableEntries) {
			result = (new Manager()).checknull(res, row);
		}

		Assert.assertEquals(result, false);
	}

	@Test
	public void test_printTable() throws FileNotFoundException, IOException {
		Manager t = new Manager();
		t.printTable();
	}

	@Test
	public void test_Vaildate() throws FileNotFoundException, IOException {
		class StubMan extends Manager {
			// Overwrite the class functions
			public StubMan(ArrayList<ClassRoom> rm) throws FileNotFoundException, IOException{
				this.ClassRoomEntries = rm;
			}
		}

		ArrayList<ClassRoom> rm = new ArrayList<ClassRoom>();
		rm.add(new ClassRoom("4102", "AC1", 250, "Blue"));

		ArrayList<Course> c = new ArrayList<Course>();
		c.add(new Course("CS3201", 10, 200, "mark"));
		c.add(new Course("CS4482", 10, 200, "joey"));
		c.add(new Course("CS2322", 10, 200, "tammy"));
		c.add(new Course("CS4280", 10, 200, "Tony"));
		c.add(new Course("CS4280", 10, 200, "Tony"));
		c.add(new Course("CS4280", 10, 200, "Tony"));
		
		StubMan stubm = new StubMan(rm);
		stubm.validate(c);
	}

	// not finished
	@Test
	public void test_checkLecturer() throws FileNotFoundException, IOException {
		ClassRoom a1 = new ClassRoom("4412", "AC2", 300, "Red");
		ClassRoom a2 = new ClassRoom("4405", "AC1", 300, "Blue");
		Course c1 = new Course("CS3206", 3, 300, "Mary Lo");
		Course c2 = new Course("CS4280", 3, 300, "Mary Lo");
		/*
		 * Course b = new Course("CS3201", "11", 300, "bernard"); Course j = new
		 * Course("CS3202", "11", 300, "joe"); Course m = new Course("CS3203",
		 * "11", 300, "mark"); Course r = new Course("CS3204", "11", 300,
		 * "bear"); Course h = new Course("CS3205", "11", 300, "hung");
		 */

		Manager t = new Manager();

		boolean result = t.checkLecturer(a2, c2);
		// t.printTable();
		Assert.assertEquals(result, true);
	}

	@Test
	public void test_write() throws FileNotFoundException, IOException{
		class StubMan extends Manager {
			// Overwrite the class functions
			public StubMan(ArrayList<ClassRoom> rm) throws FileNotFoundException, IOException{
				this.ClassRoomEntries = rm;
				for (TimeTableRow row : ClassRoomEntries.get(0).get_timetable()) {
					for (TimeTableColumn column : row) {
						this.correct_t = column;
						this.correct_w = row;
					}
				}
			}
		}

		ArrayList<ClassRoom> rm = new ArrayList<ClassRoom>();
		rm.add(new ClassRoom("4102", "AC1", 250, "Blue"));
		rm.add(new ClassRoom("4103", "AC1", 300, "Blue"));
		rm.add(new ClassRoom("4104", "AC1", 100, "Blue"));
		rm.add(new ClassRoom("4105", "AC1", 250, "Blue"));

		ArrayList<Course> c = new ArrayList<Course>();
		c.add(new Course("CS3201", 3, 200, "mark"));
		c.add(new Course("CS4482", 3, 200, "joey"));
		c.add(new Course("CS2322", 3, 200, "tammy"));
		c.add(new Course("CS4280", 3, 200, "Tony"));
		
		c.get(0).set_assigned_crm("4102");

		StubMan stubm = new StubMan(rm);
		for (Course cc : c) {
			stubm.write(cc);
		}
	}

}

/*
 * public void test_write11() throws FileNotFoundException, IOException {
 * //Course b = new Course("CS4280", 3, 300, "Mary Lo");
 * //b.set_assigned_crm("4412"); // System.out.print(b.assigned_crm); //
 * System.out.print(test); Manager f = new Manager(); for (Course res : c) {
 * f.write(res); } }
 */

